Skip to content

Data streams v2 - #1192

Open
1egoman wants to merge 104 commits into
mainfrom
data-streams-v2
Open

Data streams v2#1192
1egoman wants to merge 104 commits into
mainfrom
data-streams-v2

Conversation

@1egoman

@1egoman 1egoman commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Overview

This change introduces data streams v2, a set of major updates to data streams to add three things:

  1. Single packet data streams for short (< 15kb), finite length payloads
  2. DEFLATE compression, when both the sender and all receivers support compression/decompression
  3. A maximum 15kb size for data stream attributes to close this as a DOS vector

For information about important decisions made in data streams v2, see the spec. In particular, parts 1-5 provide a good high level overview of data streams v1 + v2, what these protocol improvements are aiming to acheive, and why certain choices were made when designing the protocol.

Also maybe of interest is the corresponding web sdk pull request.

These updates are fully backwards compatible - the sdk will fall back to data streams v1 whenever an old participant is in the room.

There is also a significant amount of new test coverage to data streams (both v1 and v2). There were some small bugs I found along the way which I fixed as well.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Changeset ✓

This PR includes a changeset covering all affected packages:

Package Bump
livekit patch
livekit-api patch
livekit-datatrack patch
livekit-ffi patch
livekit-protocol patch
livekit-uniffi patch

Comment thread examples/wgpu_room/src/app.rs Outdated
Comment thread livekit-ffi/src/conversion/data_stream.rs Outdated
Comment thread livekit/Cargo.toml
Comment thread livekit/src/room/data_stream/incoming.rs Outdated
Comment thread livekit/src/room/data_stream/outgoing.rs Outdated
Comment thread livekit-data-stream/src/outgoing/mod.rs
Comment thread livekit/src/room/data_stream/outgoing.rs Outdated
Comment thread livekit/src/room/participant/mod.rs Outdated
Comment thread livekit/src/room/rpc/mod.rs Outdated
Comment thread livekit/tests/data_stream_test.rs
Comment thread livekit/src/prelude.rs Outdated
Comment thread livekit/src/room/participant/remote_participant.rs Outdated
Comment thread livekit/src/room/participant/mod.rs Outdated
Comment thread livekit-data-stream/src/incoming/mod.rs Outdated
Comment thread livekit-data-stream/src/incoming/stream_reader.rs
Comment thread livekit-data-stream/src/outgoing/mod.rs Outdated
Comment thread livekit-data-stream/src/outgoing/mod.rs Outdated
@1egoman
1egoman marked this pull request as ready for review July 6, 2026 21:15
devin-ai-integration[bot]

This comment was marked as resolved.

@1egoman
1egoman force-pushed the data-streams-v2 branch from 15c2d7b to 9daf2a9 Compare July 8, 2026 19:21
@1egoman
1egoman marked this pull request as draft July 8, 2026 19:22
@1egoman
1egoman changed the base branch from main to data-streams-refactor July 8, 2026 19:24
devin-ai-integration[bot]

This comment was marked as resolved.

1egoman added a commit that referenced this pull request Jul 9, 2026
Breaks out a subset of the changes from
#1192 into a pull request which
exclusively moves the existing data streams implementation into its own
crate, `livekit-data-streams`, and adds a new `livekit-common` crate
(kept fairly minimal for now) for common utilities which
`livekit-data-streams` and `livekit` both need.

This is largely being scoped to a "lift and shift" type effort, more
extensive refactoring of the `livekit-data-streams` crate will be done
in #1192.

### Breaking changes

There should not be any breaking changes from the perspective of
`livekit`'s public api. If so, please surface them.

### Testing

This pull request adds the relevant v1 data streams tests from
#1192. More test coverage will
be introduced as a follow up in the data streams v2 change.

---------

Co-authored-by: Jacob Gelman <3182119+ladvoc@users.noreply.github.com>
Base automatically changed from data-streams-refactor to main July 9, 2026 20:00
@1egoman
1egoman force-pushed the data-streams-v2 branch from 339361a to 2552a56 Compare July 9, 2026 20:34
1egoman added 23 commits July 23, 2026 13:33
…er compression mechanism was added in the future

This should never happen but adding this extra check makes it just that much more bulletproof.
Test mode checks the contents of header.inline_content via is_inline, so
.take() will clear this out and cause that field to be wrong on the
receive end. However, this isn't currently being used in tests at all.
This is required for the python / node sdks to adopt the standardized
data stream implementation, since it uses this feature for (I think)
avatars
This allows configuring the data stream max payload size value when
constructing a room.
The node and python sdks today have their own data streams
implementations. If this branch were merged today, then it would mean
that the new client_protocol=2 would be advertised, and these
pre-existing implementations would receive data stream v2 messages, not
v1 (ie, single packet data streams, compression, etc).

So for now, add a flag which can be set in livekit-ffi to disable
advertising the new client protocol so this can be merged. Once merged,
node and python can be updated to pass this flag. Then, once data
streams v2 is done on both node + python and both are updated, this flag
can be removed by reverting this commit.
devin-ai-integration[bot]

This comment was marked as resolved.

);

if bytes_total.is_some_and(|total| total > self.max_payload_byte_length as u64) {
let _ = chunk_tx.send(Err(StreamError::PayloadTooLarge));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(non-blocking): Would it make sense to pass the total in the error variant for visibility?

Comment thread livekit-api/src/signal_client/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants